<?php

namespace Biz\model\redPacket;

use Doraemon\pockets\datebase\BaseDbModel;

class RedPacketsSend extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_redpacket';

    const _DATABASE_ = 'biz_red_packet';

    const _TABLE_NAME = 'red_packets_send';

    //状态码
    const STATUS_UNSEND = 0;//未发送
    const STATUS_SEND = 1;//发送中
    const STATUS_DELETE = 9;//已删除


    //状态描述
    public static $statusDesc = [
        self::STATUS_UNSEND => '未发送',
        self::STATUS_SEND => '已发送',
        self::STATUS_DELETE => '已删除'
    ];


    public static function formatInfo(&$info)
    {
        foreach ($info as $key => $value) {
            switch ($key) {
                case 'status':
                    $info['status_desc'] = isset(self::$statusDesc[$value]) ? self::$statusDesc[$value] : '';
                    break;

            }
        }
    }

    public static function addData($data)
    {
        $now = date('Y-m-d H:i:s');
        $data['addtime'] = $now;
        $data['edittime'] = $now;
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }


    public static function updateData($data, $where)
    {
        $data['edittime'] = date('Y-m-d H:i:s');
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }

}

